package com.cuitrip.component.popupmenu;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.cuitrip.business.tripservice.ui.IconTextView;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;
import com.cuitrip.util.UIUtil;
import com.lab.adapter.BaseHolderView;
import com.lab.adapter.IAdapterData;

/**
 * Created by leo on 2015/1/21.<br><br>
 */
public class PopupMenuItemHolderView extends BaseHolderView {
    private View mRootView;

    private IconTextView selectIcon;
    private TextView mTvPopupMenuTitle;
    private View mPopupMenuBottomLine;

    private PopupMenuItem mPopupMenuItem;
    
    

    public PopupMenuItemHolderView(Context context) {
        super(context, R.layout.popup_menu_list_item);
    }

    @Override
    public void initView(View rootView) {
        mRootView = rootView;
        mTvPopupMenuTitle = UIUtil.findViewById(rootView, R.id.popup_menu_title, TextView.class);
        mPopupMenuBottomLine = UIUtil.findViewById(rootView, R.id.popup_menu_bottom_line, View.class);
        selectIcon = UIUtil.findViewById(rootView, R.id.popup_menu_item_select, IconTextView.class);
    }

    @Override
    public void bindData(final IAdapterData data, final int position) {
        if (null != data) {
            mPopupMenuItem = (PopupMenuItem) data;
            // 更新Title
            if (!TextUtils.isEmpty(mPopupMenuItem.getTitle())) {
                mTvPopupMenuTitle.setText(mPopupMenuItem.getTitle());
            } else {
                mTvPopupMenuTitle.setText("");
            }
            // 更新BottomLine
            if (mPopupMenuItem.isNeedBottomLine()) {
                mPopupMenuBottomLine.setVisibility(View.VISIBLE);
            } else {
                mPopupMenuBottomLine.setVisibility(View.INVISIBLE);
            }
            
            if(mPopupMenuItem.isSelected()){
                selectIcon.setTextColor(ResourceUtil.getThemeColor());
                mTvPopupMenuTitle.setTextColor(ResourceUtil.getThemeColor());
            }else{
                selectIcon.setTextColor(getResources().getColor(R.color.ct_white));
                mTvPopupMenuTitle.setTextColor(getResources().getColor(R.color.ct_black));
            }


        }
    }

}
